/////////////////////////////////////////////////////////////////////////////
// Name:        addonsdialog.cpp
// Purpose:     
// Author:      Brant Young
// Modified by: 
// Created:     Sat Jun 23 14:55:12 2007
// RCS-ID:      
// Copyright:   (C) Victsoft 2007
// Licence:     GPL 2.0
/////////////////////////////////////////////////////////////////////////////

#include <wx/wx.h>
#include <wx/toolbook.h>
#include <wx/hyperlink.h>
#include <wx/imaglist.h>

#include "addonsdialog.h"
#include "dictpackpanel.h"
#include "extpanel.h"
#include "themepanel.h"
#include "thememgr.h"
#include "addonswizard.h"



/*!
 * AddonsDialog constructors
 */

AddonsDialog::AddonsDialog(wxWindow* p_parent)
{    
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create(p_parent, ID_ADDONS_DLG, _("Add-ons"), wxDefaultPosition, \
    		wxDefaultSize, wxCAPTION| \
    		wxSYSTEM_MENU|wxCLOSE_BOX);
    CreateControls();
    
    InitEvents();
    Fit();
    CentreOnScreen();
}

/*!
 * AddonsDialog destructor
 */

AddonsDialog::~AddonsDialog()
{
}


/*!
 * Control creation for AddonsDialog
 */

void AddonsDialog::CreateControls()
{
    p_root_sizer = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(p_root_sizer);

    /*p_addons_tbook = new wxToolbook( this, ID_ADDONS_TBOOK, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
    wxImageList* p_addons_tbookImageList = new wxImageList(32, 32, true, 4);
    {
        ThemeManager& theme_mgr = ThemeManager::get();

        wxBitmap& bmp0 = theme_mgr.get_bitmap(_T("dictpack-32.png"));
        p_addons_tbookImageList->Add(bmp0);
        
        wxBitmap& bmp1 = theme_mgr.get_bitmap(_T("extension-32.png"));
        p_addons_tbookImageList->Add(bmp1);

        wxBitmap& bmp2 = theme_mgr.get_bitmap(_T("theme-32.png"));
        p_addons_tbookImageList->Add(bmp2);
    }
    p_addons_tbook->AssignImageList(p_addons_tbookImageList);

    p_dict_panel = new DictPackPanel(p_addons_tbook);

    p_addons_tbook->AddPage(p_dict_panel, _("DictPack"), false, 0);

    p_ext_panel = new ExtensionPanel(p_addons_tbook);

    p_addons_tbook->AddPage(p_ext_panel, _("Extensions"), false, 1);

    p_theme_panel = new ThemePanel(p_addons_tbook);

    p_addons_tbook->AddPage(p_theme_panel, _("Themes"), false, 2);

    p_root_sizer->Add(p_addons_tbook, 1, wxGROW, 0);*/
    ////////
    	p_dict_panel = new DictPackPanel(this);
    	p_root_sizer->Add(p_dict_panel, 1, wxGROW, 0);
    ///////
    	
    p_button_sizer = new wxBoxSizer(wxHORIZONTAL);
    p_root_sizer->Add(p_button_sizer, 0, wxGROW|wxALL, 5);

    p_help_btn = new wxButton(this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
    p_button_sizer->Add(p_help_btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    p_button_sizer->Add(5, 5, 1, wxGROW|wxALL, 5);

    p_install_wizard_btn = new wxButton(this, ID_INSTALL_WIZARD_BTN, _("&Install Add-ons..."), wxDefaultPosition, wxDefaultSize, 0 );
    p_button_sizer->Add(p_install_wizard_btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    p_get_more_href = new wxHyperlinkCtrl(this, ID_GET_MORE_HREF, _("Get More Add-ons"), _T("http://www.daodict.org"), \
    		wxDefaultPosition, wxDefaultSize, \
    		wxHL_ALIGN_RIGHT|wxHL_DEFAULT_STYLE|wxHL_CONTEXTMENU
    		);
    
    p_button_sizer->Add(p_get_more_href, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    p_button_sizer->Add(5, 5, 1, wxGROW|wxALL, 5);

    p_ok_btn = new wxButton(this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    p_ok_btn->SetDefault();
    p_button_sizer->Add(p_ok_btn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
    
}

void AddonsDialog::InitEvents() {
	this->Connect(ID_INSTALL_WIZARD_BTN, wxEVT_COMMAND_BUTTON_CLICKED, 
			(wxObjectEventFunction)&AddonsDialog::OnInstallAddonWizard);
}

void AddonsDialog::OnInstallAddonWizard(wxCommandEvent& event) {
	InstallAddonsWizard install_addons_wizard(this);
	install_addons_wizard.run();
}
